package com.chris.easymallproduct.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.chris.easymallproduct.dto.CategoryBrandRelationDto;
import com.chris.easymallproduct.entity.AttrEntity;
import com.chris.easymallproduct.vo.BrandsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.chris.easymallproduct.entity.CategoryBrandRelationEntity;
import com.chris.easymallproduct.service.CategoryBrandRelationService;
import com.chris.common.utils.PageUtils;
import com.chris.common.utils.R;

import javax.validation.Valid;


/**
 * 品牌分类关联
 *
 * @author chris
 * @email wysiwyg7@163.com
 * @date 2022-08-14 19:42:02
 */
@RestController
@RequestMapping("easymallproduct/categorybrandrelation")
public class CategoryBrandRelationController {
    @Autowired
    private CategoryBrandRelationService categoryBrandRelationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = categoryBrandRelationService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/catelog/list")
    public R catelogList(@RequestParam("brandId") Long brandId) {
        List<CategoryBrandRelationEntity> data = categoryBrandRelationService.catelogList(brandId);
        return R.ok().put("data", data);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id);

        return R.ok().put("categoryBrandRelation", categoryBrandRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@Valid @RequestBody CategoryBrandRelationDto dto) {
        categoryBrandRelationService.save(dto);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CategoryBrandRelationEntity categoryBrandRelation) {
        categoryBrandRelationService.updateById(categoryBrandRelation);

        return R.ok();
    }


    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        categoryBrandRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/brands/list")
    public R brandsList(@RequestParam("catId") Long catId) {
        List<BrandsVo> brandsVos = categoryBrandRelationService.brandsList(catId);
        return R.ok().put("data", brandsVos);
    }


}
